#include "SeekBehaviour.h"
#include "BehaviourInfo.h"
#include "BPhysicsActor.h"
#include "Engine.h"
#include "LineDrawer.h"

void SeekBehaviour::CalcMotion(float* motion, BehaviourInfo* info, float weighting)
{
    if(!info->GetTargetActor() && !info->GetTargetPosition())
        return;

    //get the direction we want to be heading in
    btVector3 force;
    if(info->GetTargetActor())
        force = info->GetTargetActor()->GetPosition();
    else
        force = *info->GetTargetPosition();
    force -= info->GetSourceActor()->GetPosition();
    //scale it by the maximum velocity
    force.normalize();
    force *= info->GetMaxVelocity();

    //now minus the current velocity from it,
    force -= info->GetSourceActor()->GetLinearVelocity();
    Engine::Instance()->GetLineDrawer()->drawLine(info->GetSourceActor()->GetPosition(), force, btVector3(0,0,1));
    BehaviourI::FillArray(motion, &force, weighting);
}   